package limiter

import (
	"time"

	"github.com/gin-gonic/gin"
	"github.com/juju/ratelimit"
)

type LimiterInterface interface {
	Key(c *gin.Context) string
	GetBucket(key string) (*ratelimit.Bucket, bool)
	AddBucket(rules ...LimiterBucketRule) LimiterInterface
}

type Limiter struct {
	limiterBuckets map[string]*ratelimit.Bucket
}

type LimiterBucketRule struct {
	//自定义键值对名称
	Key string
	//间隔多久放N个令牌
	FillInterval time.Duration
	//令牌桶的容量
	Capacity int64
	//每次到达间隔时间后所放的具体令牌数量
	Quantum int64
}
